package com.codemonkey.lq.common.util;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Properties;

public final class PropertiesHelper {
	/**
	 * 使用指定的编码格式来读取Properites
	 * 
	 * @param path
	 * @param classLoader
	 * @param charsetName
	 * @return
	 */
	public static Properties LoadAllPropertiesWithSpecialCharset(String path,
			ClassLoader classLoader, String charsetName) {
		assert StringHelper.isNotEmpty(path);

		classLoader = (null == classLoader) ? Thread.currentThread().getContextClassLoader()
				: classLoader;
		charsetName = (StringHelper.isEmpty(charsetName)) ? "UTF-8" : charsetName;

		Properties prop = new Properties();
		try {
			prop.load(new InputStreamReader(classLoader.getResourceAsStream(path), charsetName));
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}

		return prop;
	}
}
